package com.woniuxy.patrol.controller;

import com.woniuxy.common.utils.ResponseUtil;
import com.woniuxy.patrol.service.PatrolTaskRouteService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/patrol/task-route")
public class PatrolTaskRouteController {
    @Resource
    private PatrolTaskRouteService taskRouteService;

    /**
     * 获取今日巡更趋势
     *
     * @param communityId 社区ID
     * @return 巡更趋势数据
     */
    @GetMapping("/today-trend")
    public ResponseUtil getTodayTrend(
            @RequestParam(required = false) Long communityId
    ) {
        try {
            Map<String, Object> result = taskRouteService.getTodayPatrolTrend(communityId);
            return ResponseUtil.success(result);
        } catch (Exception e) {
            log.error("获取今日巡更趋势失败", e);
            return ResponseUtil.error("获取趋势数据失败");
        }
    }
}
